/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.drifter;

/**
 *
 * @author Aaron
 */

import com.badlogic.gdx.math.Vector2;

public class Map {
    private final int mapWidth;
    private final int mapHeight;
    private final MapCell[][] cells;
    private final MapCell worldSpawn;

    public Map (int width, int height, int spawnX, int spawnY) {

        // Establish boundaries of the map.
        this.mapWidth = width;
        this.mapHeight = height;

        // Create the map tiles.
        this.cells = new MapCell[this.mapWidth][this.mapHeight];
        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                this.cells[i][j] = new MapCell(this, i, j);
            }
        }

        // Set the spawn point.
        MapCell potentialSpawn = getMapCell(spawnX, spawnY);
        if (potentialSpawn == null) {
            this.worldSpawn = getMapCell(0, 0);
        } else {
            this.worldSpawn = potentialSpawn;
        }
    }

    public int getWidth ( ) {
        return this.mapWidth;
    }

    public int getHeight ( ) {
        return this.mapHeight;
    }

    public MapCell getMapCell(int x, int y) {
        MapCell ret;
        try {
            ret = this.cells[x][y];
        } catch (ArrayIndexOutOfBoundsException e) {
            ret = null;
        }

        return ret;
    }

    public MapCell getSpawn ( ) {
        return this.worldSpawn;
    }
    
    public Map.TileEnum getTileType (Vector2 location) {
        return this.cells[Math.round(location.x)][Math.round(location.y)].getTileType();
    }

    public enum TileEnum {
        EMPTY,
        GRASS,
        TREE,
        MARTIANSOIL;
    }

}
